<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>诊断列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
        rel="stylesheet" />
    <script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>
    <style>
        .layui-fluid{
            padding: 5px;
        }
    </style>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-input-inline">
                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" placeholder="请输入诊断编码或者名称" autocomplete="off" class="layui-input" />
                    </div>
                </div> 
                <div class="layui-input-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="diagnosisSeach">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                    </button>
                </div>
            </div>
            <div class="layui-card-body">
                <div class="layui-card-body">
                    <table id="DiagnosisList" lay-filter="DiagnosisList"></table>
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script>
    layui.config({
        base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    });

    layui.define(['index', 'layer', 'form', 'element', 'table', 'laydate'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var table = layui.table;
        var $ = layui.$;
        var admin = layui.admin;
        var setter = layui.setter;
        var laydate = layui.laydate;

        var controller = {
            data: {
                tableins: null,
                list: [],//诊断
                selList: [],//当前页面查询
                search: {
                    name: "",
                },
            },
            init: function () {
                var self = this;
                this.data.list = parent.currDiagnos;
                console.log(this.data.list);
                this.listLoad();
                this.pageEvent();
                parent.getResult = function () {
                    //var checkStatus = table.checkStatus('DiagnosisList')
                    //    , data = checkStatus.data;
                    //return data;
                    return self.data.list;
                }
            },
            /****
             * 加载诊断
             * */
            listLoad: function (isInit) {
                var self = this;
                self.data.search.name = $("#name").val();
                if (self.data.tableins) {
                    if (isInit) {
                        self.data.tableins.reload({
                            where: self.data.search,
                            page: { curr: 1 }
                        })
                    } else {
                        self.data.tableins.reload({
                            where: self.data.search
                        })
                    }
                } else {
                    let url = self.getbaseurl("assistant.getDiagnosis");
                    self.data.tableins = table.render({
                        elem: '#DiagnosisList',
                        url: url,
                        height: 'full-120',
                        where: self.data.search,
                        height: 'full-110',
                        cellMinWidth: 80,
                        size: 'sm',
                        page: true,
                        even: true,
                        cols: [[
                            { type: 'checkbox', width: "10%" },
                            { field: 'ICDCode', title: '诊断编码', align: 'center', width: "20%" },
                            { field: 'Name', title: '诊断名称', align: 'center', width: "30%" },
                            { field: 'PYCode', title: '拼音码', align: 'center', width: "20%" },
                            { field: 'WBCode', title: '五笔码', align: 'center', width: "20%" },
                        ]], 
                        done: function (result, currPage, count) {//数据回调方法
                            var data = result.data;
                            self.data.selList = data;
                            if (self.data.list && self.data.list.length > 0) {
                                data.forEach(function (value, key) {
                                    var a = self.data.list.filter(res => {
                                        return res.DiagnosisCode == value.ICDCode;
                                    })
                                    if (a && a.length > 0) {
                                        $("div[lay-id='DiagnosisList'] td .layui-form-checkbox").eq(key).click();
                                    }
                                })
                            } 
                        },
                    })
                }
            },
           
            getbaseurl: function (fun) {
                var url = "/lowcode/APP20220607085949108/?fun=" + fun;
                return url;
            },
            /***
            * 监听事件
            * */
            pageEvent: function () {
                var self = this;
                form.on('submit(diagnosisSeach)', function (data) {
                    self.listLoad();
                });

                table.on('checkbox(DiagnosisList)', function (obj) {
                    if (obj.checked == true) {
                        if (obj.type == 'one') {
                            var a = self.data.list.filter(res => {
                                return res.DiagnosisCode == obj.data.ICDCode;
                            })
                            if (!a || a.length == 0) {
                                obj.data.DiagnosisCode = obj.data.ICDCode;
                                obj.data.DiagnosisName = obj.data.Name;
                                self.data.list.push(obj.data);
                            }
                        } else {
                            self.data.selList.forEach((item, index) => {
                                var a = self.data.list.filter(res => {
                                    return res.DiagnosisCode == item.ICDCode;
                                })
                                if (!a || a.length == 0) {
                                    item.DiagnosisCode = item.ICDCode;
                                    item.DiagnosisName = item.Name;
                                    self.data.list.push(item);
                                }
                            })
                        }
                    } else {
                        if (obj.type == 'one') {
                            for (var i = 0; i < self.data.list.length; i++) {
                                if (self.data.list[i].DiagnosisCode == obj.data.ICDCode) {
                                    self.data.list.splice(i, 1);
                                }
                            }
                        } else {
                            self.data.selList.forEach((item, index) => {
                                for (var i = 0; i < self.data.list.length; i++) {
                                    if (self.data.list[i].DiagnosisCode == item.ICDCode) {
                                        self.data.list.splice(i, 1);
                                    }
                                }
                            })
                        }
                    }
                    console.log(self.data.list);
                });
            },
        }
        /*
          * 入口
          */
        controller.init();
    }); 
</script>